﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GiveMeMenu.Common.Cache
{

    public sealed class PipeNode<TValue>
    {
        /// <summary>
        /// In-memory cache dictionary
        /// </summary>
        private static IList<TValue> _cache;
        private static object syncLock = new object();

        /// <summary>
        /// Cache initializer
        /// </summary>
        public PipeNode()
        {
            if (_cache == null)
            {
                lock (syncLock)
                {
                    if (_cache == null)
                    {
                        _cache = new List<TValue>();
                    }
                }
            }
        }


        /// <summary>
        /// Gets the specified key.
        /// </summary>
        /// <returns></returns>
        public IList<TValue> Get()
        {
            lock (syncLock)
            {
                return _cache;
            }
        }



        /// <summary>
        /// Adds the specified key.
        /// </summary>
        /// <param name="value">The value.</param>
        public  void Add(IList<TValue> value)
        {
            lock (syncLock)
            {
                _cache = value;
            }

        }

        /// <summary>
        /// Clears the cache.
        /// </summary>
        public void ClearCache() 
        {
            lock (syncLock)
            {
                _cache.Clear();
            }
        }

    }
}
